package som;

import java.util.ArrayList;
import java.util.List;

public class Neuron {

	private List<Double> synapse;
	
	public Neuron(int dimension, double ... position) throws IllegalArgumentException {
		if(position.length != dimension)
			throw new IllegalArgumentException("position array must have the same size as dimension");
		
		synapse = new ArrayList<Double>(dimension);
		
		for(int i=0; i<dimension; i++)
			synapse.add(position[i]);
	}
	
	public List<Double> getSynapse() {
		return synapse;
	}
	
	public void setSynapse(double ... position) {
		if(position.length != synapse.size())
			throw new IllegalArgumentException("position array must have the same size as dimension");
		
		for(int i=0; i<synapse.size(); i++)
			synapse.set(i, position[i]);
	}
	
	public double excite(Double ... x) {
		double sum = 0;
		for(int i=0; i<synapse.size(); i++)
			sum += Math.pow(x[i] - synapse.get(i), 2);
		return -sum;
	}
}
